import 'package:shared_preferences/shared_preferences.dart';

class SaveUtil {
  //读取数据
  static Future<String> getSavedByKey(String keyName) async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    String? data = await sharedPreferences
        .getString(keyName); // ignore: await_only_futures
    return data??'';
  }

  //保存数据
  static Future<bool> saveBydate(String keyName, String value) async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    bool isOk;
    if (value == null) {
      return await sharedPreferences.remove(keyName);
    }
    isOk = await sharedPreferences.setString(keyName, value);
    return isOk;
  }

  //读取数据
  static Future<List<String>> getSavedStringByKey(String keyName) async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    List<String>? data = sharedPreferences.getStringList(keyName);
    return data!;
  }

}
